Quản lý website giới thiệu và bán điện thoại di động ASP.net
19.283 lượt xem;
- giohang.aspx.cs
- project /
1 using System;
2 using System.Collections;
3 using System.Configuration;
4 using System.Data;
5 using System.Linq;
6 using System.Web;
7 using System.Web.Security;
8 using System.Web.UI;
9 using System.Web.UI.HtmlControls;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12 using System.Xml.Linq;
13 using System.Data.OleDb;
14 public partial class giohang : System.Web.UI.Page
15 {
16 GioHangData gh; HyperLink hplThongTin;
17 void nap()
18 {
19 GridView1.PageSize = 10;
20
21 if (!IsPostBack)
22 {
23 if (Session["GioHang"] != null)
24 {
25 DataTable dt = (DataTable)Session["GioHang"];
26
27 if (dt.Rows.Count == 0)
28 {
29 Panel2.Visible = true;
30 Panel3.Visible = false;
31 }
32 else
33 {
34 Panel3.Visible = true;
35 tinhtien(dt);
36 Panel2.Visible = false;
37 GridView1.DataSource = dt;
38 GridView1.DataBind();
39 foreach (GridViewRow gr in GridView1.Rows)
40 {
41 hplThongTin = (HyperLink)gr.FindControl("hplthongtin");
42 hplThongTin.NavigateUrl = "chitiet.aspx?tensp=" + gr.Cells[1].Text;
43 }
44
45 }
46
47 }
48 else
49 {
50 Panel2.Visible = true;
51 Panel3.Visible = false;
52 }
53 }
54 }
55 protected void Page_Load(object sender, EventArgs e)
56 {
57 //Download source code tại Sharecode.vn
58 GridView1.PageSize = 10;
59
60 if (!IsPostBack)
61 {
62 if (Session["GioHang"] != null)
63 {
64 DataTable dt = (DataTable)Session["GioHang"];
65
66 if (dt.Rows.Count == 0)
67 {
68 Panel2.Visible = true;
69 Panel3.Visible = false;
70 }
71 else
72 {
73 Panel3.Visible = true;
74 tinhtien(dt);
75 Panel2.Visible = false;
76 GridView1.DataSource = dt;
77 GridView1.DataBind();
78 foreach (GridViewRow gr in GridView1.Rows)
79 {
80 hplThongTin = (HyperLink)gr.FindControl("hplthongtin");
81 hplThongTin.NavigateUrl = "chitiet.aspx?tensp=" + gr.Cells[1].Text;
82 }
83
84 }
85
86 }
87 else
88 {
89 Panel2.Visible = true;
90 Panel3.Visible = false;
91 }
92 }
93 }
94 protected void btnmuatiep_Click(object sender, EventArgs e)
95 {
96 Response.Redirect("index.aspx");
97 }
98 private void tinhtien(DataTable tb)
99 {
100 double tien = 0;
101 foreach (DataRow dr in tb.Rows)
102 {
103 tien = tien + double.Parse(dr[4].ToString());
104 }
105 lbtongtien.Text = "Tổng giá trị đơn hàng: " + tien.ToString();
106 }
107 protected void btnsuagiohang_Click(object sender, EventArgs e)
108 {
109 gh = new GioHangData();
110 DataTable dt = (DataTable)Session["GioHang"];
111 foreach (GridViewRow gr in GridView1.Rows)
112 {
113 TextBox txtsl = (TextBox)gr.FindControl("txtsoluong");
114 if (Convert.ToInt32(txtsl.Text) > 0)
115 dt = gh.capNhatlai(dt, double.Parse(txtsl.Text), gr.Cells[1].Text);
116 else
117 {
118 dt = gh.xoaDong(dt, gr.Cells[1].Text);
119 if (dt.Rows.Count == 0)
120 {
121 Panel2.Visible = true;
122 Panel3.Visible = false;
123 }
124 }
125 }
126 GridView1.DataSource = dt;
127 GridView1.DataBind();
128 tinhtien(dt);
129 Session["GioHang"] = dt;
130
131 }
132 protected void btnguidon_Click(object sender, EventArgs e)
133 {
134
135 DataTable tb = new DataTable();
136
137 tb.Columns.Add("TenSP");
138 tb.Columns.Add("SoLuong");
139 tb.Columns.Add("Gia");
140 tb.Columns.Add("TongGia");
141
142 foreach (GridViewRow row in GridView1.Rows)
143 {
144 string s = row.Cells[1].Text;
145 HyperLink hp = (HyperLink)row.FindControl("hplthongtin");
146 TextBox soluong = (TextBox)row.FindControl("txtsoluong");
147 Label lbdongia = (Label)row.FindControl("lbdongia");
148 Label lbtonggia = (Label)row.FindControl("lbtonggia");
149 string sl = soluong.Text;
150 string dongia = lbdongia.Text;
151 string tonggia = lbtonggia.Text;
152 object[] dl = new object[4];
153 dl[0] = s;
154 dl[1] = sl;
155 dl[2] = dongia;
156 dl[3] = tonggia;
157 tb.Rows.Add(dl);
158 }
159 Session["hangmua"] = tb;
160 Session["tong"] = lbtongtien.Text;
161 Response.Redirect("kiemtragiohang.aspx");
162
163
164 }
165 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
166 {
167 gh = new GioHangData();
168 DataTable tb = (DataTable)Session["GioHang"];
169 tb = gh.xoaDong(tb, GridView1.Rows[e.RowIndex].Cells[1].Text);
170 GridView1.DataSource = tb;
171 GridView1.DataBind();
172 Session["GioHang"] = tb;
173 if (Session["GioHang"] != null)
174 {
175 DataTable dt = (DataTable)Session["GioHang"];
176 if (dt.Rows.Count == 0)
177 {
178 Panel2.Visible = true;
179 Panel3.Visible = false;
180 }
181 }
182 }
183 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
184 {
185
186 }
187 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
188 {
189 GridView1.PageIndex = e.NewPageIndex;
190 nap();
191 }
192 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
193 {
194 switch (e.CommandName)
195 {
196 case "capnhat":
197 gh = new GioHangData();
198 DataTable dt = (DataTable)Session["GioHang"];
199 foreach (GridViewRow gr in GridView1.Rows)
200 {
201 TextBox txtsl = (TextBox)gr.FindControl("txtsoluong");
202 if (Convert.ToInt32(txtsl.Text) > 0)
203 dt = gh.capNhatlai(dt, double.Parse(txtsl.Text), gr.Cells[1].Text);
204 else
205 {
206 dt = gh.xoaDong(dt, gr.Cells[1].Text);
207 if (dt.Rows.Count == 0)
208 {
209 Panel2.Visible = true;
210 Panel3.Visible = false;
211 }
212 }
213 }
214 GridView1.DataSource = dt;
215 GridView1.DataBind();
216 tinhtien(dt);
217 Session["GioHang"] = dt;
218 break;
219 }
220
221 }
222 protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
223 {
224
225 }
226 }
2 using System.Collections;
3 using System.Configuration;
4 using System.Data;
5 using System.Linq;
6 using System.Web;
7 using System.Web.Security;
8 using System.Web.UI;
9 using System.Web.UI.HtmlControls;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12 using System.Xml.Linq;
13 using System.Data.OleDb;
14 public partial class giohang : System.Web.UI.Page
15 {
16 GioHangData gh; HyperLink hplThongTin;
17 void nap()
18 {
19 GridView1.PageSize = 10;
20
21 if (!IsPostBack)
22 {
23 if (Session["GioHang"] != null)
24 {
25 DataTable dt = (DataTable)Session["GioHang"];
26
27 if (dt.Rows.Count == 0)
28 {
29 Panel2.Visible = true;
30 Panel3.Visible = false;
31 }
32 else
33 {
34 Panel3.Visible = true;
35 tinhtien(dt);
36 Panel2.Visible = false;
37 GridView1.DataSource = dt;
38 GridView1.DataBind();
39 foreach (GridViewRow gr in GridView1.Rows)
40 {
41 hplThongTin = (HyperLink)gr.FindControl("hplthongtin");
42 hplThongTin.NavigateUrl = "chitiet.aspx?tensp=" + gr.Cells[1].Text;
43 }
44
45 }
46
47 }
48 else
49 {
50 Panel2.Visible = true;
51 Panel3.Visible = false;
52 }
53 }
54 }
55 protected void Page_Load(object sender, EventArgs e)
56 {
57 //Download source code tại Sharecode.vn
58 GridView1.PageSize = 10;
59
60 if (!IsPostBack)
61 {
62 if (Session["GioHang"] != null)
63 {
64 DataTable dt = (DataTable)Session["GioHang"];
65
66 if (dt.Rows.Count == 0)
67 {
68 Panel2.Visible = true;
69 Panel3.Visible = false;
70 }
71 else
72 {
73 Panel3.Visible = true;
74 tinhtien(dt);
75 Panel2.Visible = false;
76 GridView1.DataSource = dt;
77 GridView1.DataBind();
78 foreach (GridViewRow gr in GridView1.Rows)
79 {
80 hplThongTin = (HyperLink)gr.FindControl("hplthongtin");
81 hplThongTin.NavigateUrl = "chitiet.aspx?tensp=" + gr.Cells[1].Text;
82 }
83
84 }
85
86 }
87 else
88 {
89 Panel2.Visible = true;
90 Panel3.Visible = false;
91 }
92 }
93 }
94 protected void btnmuatiep_Click(object sender, EventArgs e)
95 {
96 Response.Redirect("index.aspx");
97 }
98 private void tinhtien(DataTable tb)
99 {
100 double tien = 0;
101 foreach (DataRow dr in tb.Rows)
102 {
103 tien = tien + double.Parse(dr[4].ToString());
104 }
105 lbtongtien.Text = "Tổng giá trị đơn hàng: " + tien.ToString();
106 }
107 protected void btnsuagiohang_Click(object sender, EventArgs e)
108 {
109 gh = new GioHangData();
110 DataTable dt = (DataTable)Session["GioHang"];
111 foreach (GridViewRow gr in GridView1.Rows)
112 {
113 TextBox txtsl = (TextBox)gr.FindControl("txtsoluong");
114 if (Convert.ToInt32(txtsl.Text) > 0)
115 dt = gh.capNhatlai(dt, double.Parse(txtsl.Text), gr.Cells[1].Text);
116 else
117 {
118 dt = gh.xoaDong(dt, gr.Cells[1].Text);
119 if (dt.Rows.Count == 0)
120 {
121 Panel2.Visible = true;
122 Panel3.Visible = false;
123 }
124 }
125 }
126 GridView1.DataSource = dt;
127 GridView1.DataBind();
128 tinhtien(dt);
129 Session["GioHang"] = dt;
130
131 }
132 protected void btnguidon_Click(object sender, EventArgs e)
133 {
134
135 DataTable tb = new DataTable();
136
137 tb.Columns.Add("TenSP");
138 tb.Columns.Add("SoLuong");
139 tb.Columns.Add("Gia");
140 tb.Columns.Add("TongGia");
141
142 foreach (GridViewRow row in GridView1.Rows)
143 {
144 string s = row.Cells[1].Text;
145 HyperLink hp = (HyperLink)row.FindControl("hplthongtin");
146 TextBox soluong = (TextBox)row.FindControl("txtsoluong");
147 Label lbdongia = (Label)row.FindControl("lbdongia");
148 Label lbtonggia = (Label)row.FindControl("lbtonggia");
149 string sl = soluong.Text;
150 string dongia = lbdongia.Text;
151 string tonggia = lbtonggia.Text;
152 object[] dl = new object[4];
153 dl[0] = s;
154 dl[1] = sl;
155 dl[2] = dongia;
156 dl[3] = tonggia;
157 tb.Rows.Add(dl);
158 }
159 Session["hangmua"] = tb;
160 Session["tong"] = lbtongtien.Text;
161 Response.Redirect("kiemtragiohang.aspx");
162
163
164 }
165 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
166 {
167 gh = new GioHangData();
168 DataTable tb = (DataTable)Session["GioHang"];
169 tb = gh.xoaDong(tb, GridView1.Rows[e.RowIndex].Cells[1].Text);
170 GridView1.DataSource = tb;
171 GridView1.DataBind();
172 Session["GioHang"] = tb;
173 if (Session["GioHang"] != null)
174 {
175 DataTable dt = (DataTable)Session["GioHang"];
176 if (dt.Rows.Count == 0)
177 {
178 Panel2.Visible = true;
179 Panel3.Visible = false;
180 }
181 }
182 }
183 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
184 {
185
186 }
187 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
188 {
189 GridView1.PageIndex = e.NewPageIndex;
190 nap();
191 }
192 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
193 {
194 switch (e.CommandName)
195 {
196 case "capnhat":
197 gh = new GioHangData();
198 DataTable dt = (DataTable)Session["GioHang"];
199 foreach (GridViewRow gr in GridView1.Rows)
200 {
201 TextBox txtsl = (TextBox)gr.FindControl("txtsoluong");
202 if (Convert.ToInt32(txtsl.Text) > 0)
203 dt = gh.capNhatlai(dt, double.Parse(txtsl.Text), gr.Cells[1].Text);
204 else
205 {
206 dt = gh.xoaDong(dt, gr.Cells[1].Text);
207 if (dt.Rows.Count == 0)
208 {
209 Panel2.Visible = true;
210 Panel3.Visible = false;
211 }
212 }
213 }
214 GridView1.DataSource = dt;
215 GridView1.DataBind();
216 tinhtien(dt);
217 Session["GioHang"] = dt;
218 break;
219 }
220
221 }
222 protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
223 {
224
225 }
226 }